/**
 * materialPreview
 */
define(['jquery'], function ($) {
	var MaterialPreview;
	MaterialPreview = (function () {
		function MaterialPreview(){
		}
		MaterialPreview.prototype.previewMultiple = function ($container, materialInfo, materialId) {

      // $creativeMaterialDefault = $('#creative_material_default');
      var info = materialInfo || {},
      width = info['width'],
      height = info['height'],
      type = info['type'],
      address = info['address'],
      $creativeMaterialDefault = $container.siblings('.creative_material_default'),
      previewTxt;
      if (!info || !width || !height || !type || !address) {
        $creativeMaterialDefault.show();
        return;
      };
      // console.log(type);
      $creativeMaterialDefault.hide();
      if (type === 'swf') {
        previewTxt = '<div class="img-thumbnail">'
                   + '<div style="position: relative; z-index: 1; width: ' + width + 'px; height: ' + height + 'px;">'
                   + '<div style="position: absolute; left: 0px; top: 0px; z-index: 2; width: ' + width + 'px; height: ' + height + 'px;">'
                   + '<object codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + width + '" height="' + height + '" type="application/x-shockwave-flash">'
                   + '<param name="Movie" value="' + address + '">'
                   + '<param name="FlashVars" value="sl_clickurl=#">'
                   + '<param name="WMode" value="Opaque">'
                   + '<param name="Quality" value="High">'
                   + '<param name="AllowScriptAccess" value="always">'
                   + '<param name="Scale" value="ShowAll">'
                   + '<param name="AllowNetworking" value="all">'
                   + '<param name="AllowFullScreen" value="false">'
                   + '<embed width="' + width + 'px" height="' + height + 'px" src="' + address + '" quality="High" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="Opaque" allowscriptaccess="always" flashvars="sl_clickurl=#">'
                   + '</object>'
                   + '</div>'
                   + '</div>'
                   + '</div>';
      } else if (type === 'flv') {
        previewTxt = '<div class="flowplayer">'
                   + '<video width="' + width + '" height="' + height + '">'
                   + '<source src="' + address + '" type="video/flv" />'
                   + '</video></div>';
      } else if (type === 'mp4') {
        previewTxt = '<div class="flowplayer">'
                   + '<video width="' + width + '" height="' + height + '">'
                   + '<source src="' + address + '" type="video/mp4" />'
                   + '</video></div>';
      } else if (type === 'ogv' || type === 'ogg') {
        previewTxt = '<div class="flowplayer">'
                   + '<video width="' + width + '" height="' + height + '">'
                   + '<source src="' + address + '" type="video/ogg" />'
                   + '</video></div>'; 
      } else if (type === 'webm') {
        previewTxt = '<div class="flowplayer">'
                   + '<video width="' + width + '" height="' + height + '">'
                   + '<source src="' + address + '" type="video/webm" />'
                   + '</video></div>';
      } else {
        previewTxt = '<img class="img-thumbnail creative_material_preview" src=" '+ address + '" style="max-width: 310px; max-height: 260px;">';
      };
      previewTxt = "<div class=\"creative-preview\">"
                 + previewTxt
                 + "<input name=\"upload_material[]\" type=\"hidden\" value=\"" + materialId + "\">"
                 + "<button class=\"btn btn-link btn-s btn-sm preview-close\">" + VAM.j('Delete') + "</button>"
                 + "</div>"
      // console.log(previewTxt);
      if (info['role']) {
        $container.children().remove();
      };
      // $container.children().remove();
      $container.append(previewTxt);

    };
    MaterialPreview.prototype.previewSingle = function  ($container, materialInfo, materialId) {

      $creativeMaterialDefault = $('#creative_material_default');
      var info = materialInfo || {},
      width = info['width'],
      height = info['height'],
      type = info['type'],
      address = info['address'],
      $creativeMaterialDefault = $container.siblings('.creative_material_default'),
      previewTxt;
      // console.log(info);
      if (!info || !width || !height || !type || !address) {
        $creativeMaterialDefault.show();
        return;
      };
      // console.log(type);
      $creativeMaterialDefault.hide();
      if (type === 'swf') {
        previewTxt = '<div class="img-thumbnail">'
                   + '<div style="position: relative; z-index: 1; width: ' + width + 'px; height: ' + height + 'px;">'
                   + '<div style="position: absolute; left: 0px; top: 0px; z-index: 2; width: ' + width + 'px; height: ' + height + 'px;">'
                   + '<object codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + width + '" height="' + height + '" type="application/x-shockwave-flash">'
                   + '<param name="Movie" value="' + address + '">'
                   + '<param name="FlashVars" value="sl_clickurl=#">'
                   + '<param name="WMode" value="Opaque">'
                   + '<param name="Quality" value="High">'
                   + '<param name="AllowScriptAccess" value="always">'
                   + '<param name="Scale" value="ShowAll">'
                   + '<param name="AllowNetworking" value="all">'
                   + '<param name="AllowFullScreen" value="false">'
                   + '<embed width="' + width + 'px" height="' + height + 'px" src="' + address + '" quality="High" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="Opaque" allowscriptaccess="always" flashvars="sl_clickurl=#">'
                   + '</object>'
                   + '</div>'
                   + '</div>'
                   + '</div>';
      } else if (type === 'flv') {
        previewTxt = '<div class="flowplayer">'
                   + '<video width="' + width + '" height="' + height + '">'
                   + '<source src="' + address + '" type="video/flv" />'
                   + '</video></div>';
      } else if (type === 'mp4') {
        previewTxt = '<div class="flowplayer">'
                   + '<video width="' + width + '" height="' + height + '">'
                   + '<source src="' + address + '" type="video/mp4" />'
                   + '</video></div>';
      } else if (type === 'ogv' || type === 'ogg') {
        previewTxt = '<div class="flowplayer">'
                   + '<video width="' + width + '" height="' + height + '">'
                   + '<source src="' + address + '" type="video/ogg" />'
                   + '</video></div>'; 
      } else if (type === 'webm') {
        previewTxt = '<div class="flowplayer">'
                   + '<video width="' + width + '" height="' + height + '">'
                   + '<source src="' + address + '" type="video/webm" />'
                   + '</video></div>';
      } else {
        previewTxt = '<img class="img-thumbnail creative_material_preview" src=" '+ address + '" style="max-width: 310px; max-height: 260px;">';
      };
      // console.log(previewTxt);
      $container.children().remove();
      $container.append(previewTxt);    
    };
		return MaterialPreview;
	})();

	return new MaterialPreview();
});